﻿using UnityEngine;
using System.Collections;
 
 namespace  Example_0003_screenpoint
 {
	 public class NewBehaviourScript : MonoBehaviour {
 
		Canvas canvas;
		RectTransform rectTransform;
		// Use this for initialization
		void Start () 
		{ 
			rectTransform = transform as RectTransform;
			canvas = GameObject.Find("Canvas").GetComponent<Canvas>();
		}
		
		// Update is called once per frame
		void Update () {
			Vector2 pos;
			if(RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.transform as RectTransform, Input.mousePosition, canvas.worldCamera, out pos)){
				rectTransform.anchoredPosition = pos;
			}
		}
	}
 }
